package com.flower.service.impl;

import com.flower.mapper.SaleMapper;
import com.flower.model.dto.SalePageQueryDTO;
import com.flower.model.entity.Sale;
import com.flower.result.PageResult;
import com.flower.result.SalePageResult;
import com.flower.service.SaleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@SuppressWarnings("all")
/**
 *@ClassName SaleServiceImpl
 *@Description TODO
 *@Author @O_o  GW__
 *@Date 2025/6/17 12:57
 *@Version 1.0
 */
@Service
public class SaleServiceImpl implements SaleService {
    @Autowired
    private SaleMapper saleMapper;
    @Override
    public PageResult getSaleList(SalePageQueryDTO salePageQueryDTO) {
        PageHelper.startPage(salePageQueryDTO.getPageNum(), salePageQueryDTO.getPageSize());
        Page<Sale> page = saleMapper.getSaleList(salePageQueryDTO);
        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public void addOrUpdate(Sale sale) {
        if(sale.getId()==0){
            saleMapper.add(sale);
        }else {
            saleMapper.update(sale);
        }
    }

    @Override
    public void deleteSale(Integer id) {
        saleMapper.deleteSaleById(id);
    }

    @Override
    public void deleteSaleList(List<Integer> ids) {
        ids.forEach(id->saleMapper.deleteSaleById(id));
    }

    @Override
    public PageResult getPassSale(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<Sale> page = saleMapper.getPassSale();
        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public List<Sale> list() {
        return saleMapper.list();
    }
}
